import { Injector } from "../../base/utils/Injector";
import { INativeHelper } from "./INativeHelper";

/*
@name: NativeHelper
@desc: 原生函数调用代理
@author: timoo
@date: 2022/11/26
*/
export class NativeHelper
{
    static KEY:string="NativeHelper";

    public static call(className:string, methodName:string, ...args):void{
        NativeHelper.impl.call(className, methodName, ...args);
    }

    public static callWithReturnType(className:string, methodName:string, returnType:string | boolean | number, ...args):string | boolean | number{
        return NativeHelper.impl.callWithReturnType(className, methodName, returnType, ...args);
    }

    public static registerCallback(caller:any, method:Function, times:number, ...args):string{
        return NativeHelper.impl.registerCallback(caller, method, times, ...args);
    }

    public static registerCallbackOnce(caller:any, method:Function, ...args):string{
        return NativeHelper.impl.registerCallback(caller, method, 1, ...args);
    }

    private static _impl:INativeHelper;
    static get impl():INativeHelper{
        if(this._impl==null){
            this._impl = Injector.getInject(NativeHelper.KEY);
        }
        if (this._impl == null) {
            throw new Error(NativeHelper.KEY+" 未注入!");
        }
        return this._impl;
    }
}
